/**
@file baseexception.h
@brief BaseException class definition

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 3 of the License.

@author VestniK (Sergey N.Vidyuk)
 */
#ifndef _BaseException_H_
#define _BaseException_H_

#include <QtCore/QString>

namespace mjn {

   /**
   @brief Base class for all exceptions in the project.

   All exception in this project shoud be subclassed from this class. If some class member is going to throw exception specific only for that class, exception should be defined in public section of that class. Every exception class should fill reason string in constructor and call addStdPrefix() method with full exception class name.
   */
   class BaseException {
      public:
         BaseException(const QString& what="") {addStdPrefix("mjn::BaseException"); reason += what;};

         /// Returns error reason
         virtual const QString& getReason() {return reason;};

         virtual ~BaseException() {};
      protected:
         /// Adds standart prefix to reason string.
         void addStdPrefix(const QString& class_name) {
            reason = class_name+" exception. Reason:\n\t" + reason;
         };
         /**
         @brief Error reason

         Fill this string in your subclass constructor. Don't forget to use addStdPrefix() with your class name as argument.
         */
         QString reason;
   }; // class BaseException

} // namespace mjn

#endif // _BaseException_H_
